package com.lsp.microcommon.utils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class DateUtils {



//    获取当前日期的年月
    public static String getYearAndMouth(){
        LocalDate now = LocalDate.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        String yearAndMonth = year + "-" + month;
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
//        String format = formatter.format(now);
        return yearAndMonth;
    }

    public static String getYearAndMouthAndDay(){
        LocalDate now = LocalDate.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        int dayOfMonth = now.getDayOfMonth();
        String yearAndMonthAndDay = year + "-" + month + "-" + dayOfMonth;
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
//        String format = formatter.format(now);
        return yearAndMonthAndDay;
    }

    public static String getLastYearAndMouthAndDay(){
        LocalDate now = LocalDate.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        int dayOfMonth = now.getDayOfMonth() - 1;
        String yearAndMonthAndDay = year + "-" + month + "-" + dayOfMonth;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        String format = formatter.format(now);

//        LocalDate localDate = LocalDate.now().minusDays(1L);

        return yearAndMonthAndDay;
    }

    public static int getDay(){
        return LocalDate.now().getDayOfMonth();
    }
}
